<template>
  <div>
    <video
      src="https://slwl-admin.itheima.net/static/media/video.3cf57b17.mp4"
      autoplay="autoplay"
      loop="loop"
      muted="muted"
      style="width: 100%; height: 100%; object-fit: fill"
    />
    <div class="login-container">
      <el-form ref="loginForm" :model="loginForm" :rules="rules">
        <img
          class="slwl"
          src="https://slwl-admin.itheima.net/static/img/logo1.33ef7fa0.png"
          alt=""
        >
        <div class="Uniform">
          <el-form-item prop="mobile" class="firstm">
            <el-input
              v-model="loginForm.mobile"
              placeholder="账号"
              type="text"
            />
            <img
              class="caret1"
              src=""
            >
          </el-form-item>
          <el-form-item prop="password" class="secondm">
            <el-input
              ref="eyes"
              v-model="loginForm.password"
              placeholder="密码"
              type="password"
            />
            <img
              class="caret2"
              src=""
              alt=""
            >
            <i class="el-icon-view" @click="eye" />
          </el-form-item>
          <el-form-item label-width="90" class="threem" prop="authcode">
            <el-input v-model="loginForm.authcode" placeholder="验证码" type="text" />
            <!-- <i class="el-icon-check" /> -->
            <img
              class="caret3"
              src=""
              alt=""
            >
            <div class="tp" @click="yzm">
              <img :src="url" alt="" class="code-image">
            </div>
          </el-form-item>
          <el-form-item class="button">
            <el-button type="primary" @click="hlogin">登录</el-button>
          </el-form-item>
          <p>
            仅用于IT培训教学使用,为保障你的个人信息安全,请勿向平台录人任何个人敏感信息(如手机号,身份证等)
            !
          </p>
        </div>
      </el-form>

    </div>

  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'Login',
  data() {
    return {
      // 点击眼睛开关的值
      eyess: false,
      url: '',
      loginForm: {
        mobile: 'shenlingadmin',
        password: '123456',
        authcode: ' '
      },
      rules: {
        mobile: [
          { required: true, message: '帐号不能为空', tigger: 'blur' },
          {
            pattern: /^\S{6,}$/,
            message: '帐号格式不正确',
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '密码不能为空', tigger: 'blur' },
          { pattern: /^\S{5,}$/, message: '密码格式不正确', trigger: 'blur' }
        ],
        authcode: [
          { required: true, message: '验证码不能为空', tigger: 'blur' },
          { pattern: /^\d+$/, message: '验证码格式不正确', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.yzm()
  },
  methods: {
    // 点击eye 密码框转文本
    eye() {
      this.eyess = !this.eyess
      // this.$refs.eyes.type = 'text'
      this.eyess ? this.$refs.eyes.type = 'text' : this.$refs.eyes.type = 'password'

      if (this.eyess) {
        this.$refs.eyes.type = 'text'
      } else {
        this.$refs.eyes.type = 'password'
      }
    },
    // 封装图片请求
    async yzm() {
      const res = await axios({
        url: '/manager/captcha',
        params: {
          key: 1
        },
        responseType: 'arraybuffer'
      })
      console.log(res.data)
      // document.write(res.data)
      this.url = `data: image/jpeg;base64,${btoa(new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), ''))}`
    },
    doLogin() {
      console.log('做具体登录操作(发请求)')
      this.$store.dispatch('user/login', this.loginForm)
      this.$router.push('/')
    },
    hlogin() {
      // console.log(this.$refs.form.validate)
      this.$refs.loginForm.validate((vaild) => {
        if (vaild) {
          // 做具体操作发请求
          // this.doLogin()
          // alert('校验通过')
          this.doLogin()
        }
        // vaild && this.doLogin()
      })
    }

  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-input__inner {
  height: 50px;
  border: 1px solid #e15536;
}
.login-container {
  background-color: #fff;
  position: absolute;
  top: 45%;
  left: 45%;
  margin: -180px 0 0 -160px;
  width: 450px;
  height: 490px;
  padding: 36px 40px;
  // background: #fff;
  border-radius: 10px;

  .slwl {
    width: 195px;
    height: 54px;
    margin-left: 20%;
    margin-bottom: 30px;
  }

  ::v-deep .el-button {
    margin-top: 17px;
    width: 370px;
    height: 54px;
    font-size: 18px;
    font-weight: 600;
  }
  p {
    font-size: 14px;
    margin: 10px;
    color: #e15536;
  }
  .fisrtm {
    position: relative;
  }
  .secondm {
    position: relative;
  }
  .threem {
    position: relative;
  }
  .caret1 {
    position: absolute;
    top: 15px;
    left: 10px;
    width: 21px;
    height: 21px;
  }
  .caret2 {
    position: absolute;
    top: 15px;
    left: 10px;
    width: 21px;
    height: 21px;
  }
  .caret3 {
    position: absolute;
    top: 15px;
    left: 10px;
    width: 21px;
    height: 21px;
  }
  ::v-deep .el-icon-view {
    position: absolute;
    top: 19px;
    right: 10px;
    width: 21px;
    height: 21px;

  }
  ::v-deep .el-input__inner {
    padding-left: 40px;
  }
  .tp{
    width: 51px;
    height: 32px;
     position: absolute;
    top: 5px;
    right: 70px;
  }
}

</style>
